package netty.heartBeat;

import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;
import io.netty.handler.timeout.IdleStateEvent;

/**
 * @Description TODO
 * @Author 李龙平
 * @Date 2020/10/13 14:37
 */
public class MyServerHandler extends ChannelInboundHandlerAdapter {

    @Override
    public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception {
        //判断时间类型
        if (evt instanceof IdleStateEvent) {
            IdleStateEvent event = (IdleStateEvent)evt;
            switch (event.state()) {
                case READER_IDLE:
                    System.out.println("读空闲");
                    break;
                case ALL_IDLE:
                    System.out.println("全空闲");
                    break;
                case WRITER_IDLE:
                    System.out.println("写空闲");
                    break;
                default:
            }
        }
        System.out.println(ctx.channel() + "发生了空闲");
    }
}
